﻿using DataAchive.Common;
using DataAchive.Model.Excel.Export;
using DataAchive.Model.Excel.Export.Fanxiu;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAchive.Helper
{
    public class FanXiuReportHelper
    {

        public static List<FanXiuColRowReport> DicToFanXiuList(List<Dictionary<string, object>> listPairs)
        {
            if (listPairs == null || listPairs.Count == 0)
            {
                return new List<FanXiuColRowReport>();
            }
            List<FanXiuColRowReport> reports = new List<FanXiuColRowReport>();
            foreach (var dics in listPairs)
            {
                FanXiuColRowReport report1 = new FanXiuColRowReport();
                foreach (KeyValuePair<string, object> item in dics)
                {
                    try
                    {
                        if (item.Key.Equals("lotid", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.LotId = "";
                            }
                            else
                            {
                                report1.LotId = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("checked", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.Checked = 0;
                            }
                            else
                            {
                                report1.Checked = Convert.ToInt32(item.Value);
                            }
                        }
                        else if (item.Key.Equals("ELJilu", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.ElCreateTime = DateTime.MinValue;
                            }
                            else
                            {
                                report1.ElCreateTime = Convert.ToDateTime(item.Value);
                            }
                        }
                        else if (item.Key.Equals("VIJilu", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VICreateTime = DateTime.MinValue;
                            }
                            else
                            {
                                report1.VICreateTime = Convert.ToDateTime(item.Value);
                            }
                        }

                        else if (item.Key.Equals("VBJilu", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VBCreateTime = DateTime.MinValue;
                            }
                            else
                            {
                                report1.VBCreateTime = Convert.ToDateTime(item.Value);
                            }
                        }

                        else if (item.Key.Equals("checked", StringComparison.OrdinalIgnoreCase))
                        {

                        }

                        else if (item.Key.Equals("id", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.Id = -1;
                            }
                            else
                            {
                                report1.Id = Convert.ToInt32(item.Value);
                            }
                        }
                        else if (item.Key.Equals("site_id", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.SiteId = -1;
                            }
                            else
                            {
                                report1.SiteId = Convert.ToInt32(item.Value);
                            }
                        }
                        else if (item.Key.Equals("ELwancheng", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.ElFinishTime = DateTime.MinValue;
                            }
                            else
                            {
                                report1.ElFinishTime = Convert.ToDateTime(item.Value);
                            }
                        }
                        else if (item.Key.Equals("VIwancheng", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VIFinishTime = DateTime.MinValue;
                            }
                            else
                            {
                                report1.VIFinishTime = Convert.ToDateTime(item.Value);
                            }
                        }
                        else if (item.Key.Equals("VBwancheng", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VBFinishTime = DateTime.MinValue;
                            }
                            else
                            {
                                report1.VBFinishTime = Convert.ToDateTime(item.Value);
                            }
                        }
                        else if (item.Key.Equals("ELairesult", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.ElAiDetectResult = "";
                            }
                            else
                            {
                                report1.ElAiDetectResult = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VIairesult", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VIAiDetectResult = "";
                            }
                            else
                            {
                                report1.VIAiDetectResult = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VBairesult", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VBAiDetectResult = "";
                            }
                            else
                            {
                                report1.VBAiDetectResult = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("ELRengongResult", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.ElHumanDetectResult = "";
                            }
                            else
                            {
                                report1.ElHumanDetectResult = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VIRengongResult", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VIHumanDetectResult = "";
                            }
                            else
                            {
                                report1.VIHumanDetectResult = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VBRengongResult", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VBHumanDetectResult = "";
                            }
                            else
                            {
                                report1.VBHumanDetectResult = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("mes_check", StringComparison.OrdinalIgnoreCase))
                        {

                        }
                        else if (item.Key.Equals("line_id", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.LineId = "";
                            }
                            else
                            {
                                report1.LineId = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("equipment_id", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.Equipment = "";
                            }
                            else
                            {
                                report1.Equipment = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("classify", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.Classify = "";
                            }
                            else
                            {
                                report1.Classify = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("ELAiQX", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.ElAiDetectInfo = "";
                            }
                            else
                            {
                                report1.ElAiDetectInfo = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VIAiQX", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.ViAiDetectInfo = "";
                            }
                            else
                            {
                                report1.ViAiDetectInfo = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VBAiQX", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VBAiDetectInfo = "";
                            }
                            else
                            {
                                report1.VBAiDetectInfo = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("ELrengongQX", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.ElHumanDetectInfo = "";
                            }
                            else
                            {
                                report1.ElHumanDetectInfo = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VIrengongQX", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VIHumanDetectInfo = "";
                            }
                            else
                            {
                                report1.VIHumanDetectInfo = item.Value.ToString();
                            }
                        }
                        else if (item.Key.Equals("VBrengongQX", StringComparison.OrdinalIgnoreCase))
                        {
                            if (item.Value is null)
                            {
                                report1.VBHumanDetectInfo = "";
                            }
                            else
                            {
                                report1.VBHumanDetectInfo = item.Value.ToString();
                            }
                        }


                    }
                    catch (Exception ee)
                    {

                        SoftCommon.Log.Write("transfer err:" + ee.Message);
                        continue;
                    }


                }

                reports.Add(report1);
            }

            return reports;

        }

       
    }
}
